package com.ewzj.bigdata.mvp.model

import android.app.Application
import com.ewzj.bigdata.app.config.netmodel.CommonCache
import com.ewzj.bigdata.app.config.netmodel.CommonService
import com.ewzj.bigdata.app.utils.Apputils
import com.ewzj.bigdata.mvp.contract.InformercialActivityContract
import com.ewzj.bigdata.mvp.model.reqbean.Reqpagebean
import com.ewzj.bigdata.mvp.model.rspbean.BaseData
import com.ewzj.bigdata.mvp.model.rspbean.BaseListData
import com.ewzj.bigdata.mvp.model.rspbean.RspOriginBean
import com.google.gson.Gson
import com.jess.arms.base.BaseApplication
import com.jess.arms.integration.IRepositoryManager
import com.jess.arms.mvp.BaseModel
import com.jess.arms.utils.DeviceUtils
import io.reactivex.Observable
import io.rx_cache2.DynamicKey
import io.rx_cache2.EvictDynamicKey
import javax.inject.Inject

/**
 * author:zhangjing
 * 作用:
 * return:
 */
class InformercialActivityModel @Inject constructor(val context: Application, val mGson: Gson, repositoryManager: IRepositoryManager): BaseModel(repositoryManager),InformercialActivityContract.Model{
    val service:CommonService by lazy { repositoryManager.obtainRetrofitService(CommonService::class.java) }
    val cacheservice: CommonCache by lazy { repositoryManager.obtainCacheService(CommonCache::class.java) }
    override fun loadInformercialData(reqpagebean: Reqpagebean):  Observable<List<RspOriginBean>>  {
        return cacheservice.orginTopicV3(service.orginTopicV3(Apputils.Utils.json2Requestbody(mGson.toJson(reqpagebean))).map { t: BaseData<BaseListData<RspOriginBean>> ->t.data!!.list  }
                , DynamicKey(reqpagebean.news_type.plus(reqpagebean.p)), EvictDynamicKey(DeviceUtils.hasInternet(context)))
    }

}